var _ajax = $.ajax;  
$.ajax = function(options){ 
	 $("#loading",window.top.document).append('<div class="loading"  class="loading">加载中。。。</div>'); 
    var _opt = $.extend(
       {
    	beforeSend   :  function(request){
    		 
    	      
    	},complete   :  function(response, statusText){
    		$("#loading .loading",window.top.document).last().remove();  
    	}, error      :  function(response,statusText){  
    		 var result = response.responseJSON; 
    		 bug(response,result,options); 
       }
    
    },options); 
    

    _opt.success   =   function(response,statusText){ 
    	 if(response.status){
    		 options.success(response);
    	 }else{  
    		 bug(null,response,_opt);
    	 }  
    } 
    _ajax(_opt);
}
 
 function bug(response,result,options){  
	 if(response && response.status != 200){
		 window.top.toastr.warning("系统发生未知异常，响应状态码:"+response.status); 
		 return;
	 }  
	 //未登录
	 if(result.code == "4010000000"){ 
	   window.top.$(".un_login").remove();
	   window.top.toastr.warning("您还未登录,系统将在3秒后跳转登录页面","",{"toastClass":"un_login"});
	   setTimeout(function () {
		 window.top.location.href = URL.WEB_FRAMEWORK + '/templates/login.html';
	   }, 3000);
	 //未授权
	 }else if(result.code == "4030000000"){  
		 window.top.toastr.warning("未授权:  "+options.url);
	 //执行异常
	 }else if(result.code == "5000000000"){ 
		 $("#bug",window.top.document).show().on("click",function(){
			  var w = window.open();
			  var html = window.top.$("#bug_details").html(); 
			  $(w.document.body).html("<pre style='font: 1em Georgia, serif;line-height:1.4;'>"+html+"</pre>");
		 }); 
		 window.top.toastr.warning(result.msg); 
		 window.top.$("#bug_details").html(result.detailMsg);
	 //业务异常	 
	 }  if(result.code == "6000000000"){
		 window.top.toastr.warning(result.msg);  
	 }  
	
 }

 
 
